#include <stdio.h>
#include <stdlib.h>

struct list {
  struct list *next;
  struct list *prev;
  int data;
};

void init(struct list **);
void add_data(struct list *, int);
void display(struct list *);
void del_data(struct list *,int);

int main(int argc,const char** argv)
{
  struct list* head;
  init(&head);
  add_data(head,1);
  add_data(head,2);
  add_data(head,3);
  add_data(head,4);
  add_data(head,5);
  add_data(head,6);
  add_data(head,7);
  display(head);
  del_data(head,1);
  del_data(head,2);
  del_data(head,3);
  del_data(head,4);
  del_data(head,5);
  del_data(head,6);
  display(head);
}

void init(struct list **head)
{
  *head = malloc(sizeof(struct list));
  (*head)->next = (*head)->prev = *head;
}
void add_data(struct list *head, int data)
{
  struct list* new_node;
  new_node = malloc(sizeof(struct list));
  new_node->next = head;
  new_node->prev = head->prev;
  new_node->data = data;

  head->prev->next = new_node;
  head->prev = new_node;
}
void display(struct list *head)
{
  if(head->next == head)
  {
    printf("empty\n");
    return;
  }

  struct list* pos;
  pos = head->next;

  while(pos != head)
  {
    printf("%d ",pos->data);
    pos = pos->next;
  }

  printf("\n");
}

void del_data(struct list *head,int data){
  if(head->next == head)
  {
    printf("empty\n");
    return;
  }

  struct list* pos;
  pos = head->next;

  while(pos != head)
  {
    if(pos->data == data)
    {
      pos->next->prev = pos->prev;
      pos->prev->next = pos->next;
      free(pos);
      return;
    }
    else
    {
      pos = pos->next;
    }
  }

  printf("no find\n");
}

